#Replication Material for Rainbow Consciousness? Exploring the Political Outcomes and Dynamics of Queer Linked Fate
#Author: Nick D'Amico
  #e: ncdamico@syr.edu
#February 2025

#Dataset, Codebook and additional CMPS 2016 documentation can be obtained at:
# https://www.icpsr.umich.edu/web/RCMD/studies/38040

#Import data file into R Project
load(file='38040-0001-Data.rda')

#duplicate/rename data
cmps2016<-da38040.0001
#full dataset is now called cmps2016.

##########
#Install and call packages
#if packages are not installed, use install.packages('packagename') before running library('packagename')
library(questionr)
library(ggplot2)
library(dplyr)
library(sjPlot)
library(Hmisc)
library(stargazer)

##########
#Data cleaning

##RECODING LGBTQ VARIABLES##
table(cmps2016$C237)
class(cmps2016$C237)
#create numeric LGBTQ variable
# 1 = straight, 2= gay, 3= lesbian, 4= bisexual, 5= Trans, 6=Queer, 7=Other
cmps2016$lgbtq.n<-as.numeric(cmps2016$C237)
freq(cmps2016$lgbtq.n)

#create straight binary variable
cmps2016$hetero<-ifelse(cmps2016$lgbtq.n=='1',1,0)
freq(cmps2016$hetero)
#create gay binary variable
cmps2016$gay<-ifelse(cmps2016$lgbtq.n == '2',1,0)
freq(cmps2016$gay)
  # $gay is gay binary variable, 198 gay individuals in sample
#create lesbian binary variable
cmps2016$lesbian<-ifelse(cmps2016$lgbtq.n == '3',1,0)
freq(cmps2016$lesbian)
  #$lesbian is lesbian binary variable, 142 lesbian individuals in sample
#create bisexual binary variable
cmps2016$bisexual<-ifelse(cmps2016$lgbtq.n == '4',1,0)
  #$bisexual is bi binary variable, 415 bisexual individuals in sample
#create transgender binary variable
cmps2016$transgender<-ifelse(cmps2016$lgbtq.n == '5',1,0)
  #$transgender is trans binary variable, 49 trans individuals in sample
#create queer binary variable
cmps2016$queer<-ifelse(cmps2016$lgbtq.n == '6',1,0)
  #$queer is binary variable for non l,g,b,t individuals in sample, 71 total.
#create lesbian gay binary variable
cmps2016$lesbiangay <- ifelse(cmps2016$lgbtq.n == '2', 1,
                              ifelse(cmps2016$lgbtq.n == '3', 1, 0))
  #$lesbiangay is binary variable for LG=1, 340 total

#relevel LGBTQ variable where 0 = Straight, 1 = gay, 2 = lesbian, 3 = bisexual, 4= transgender, 5=queer, NA are other (will return to the others)

cmps2016$lgbtq.1<-ifelse(cmps2016$lgbtq.n == '1',0,
                         ifelse(cmps2016$lgbtq.n == '2', 1,
                                ifelse(cmps2016$lgbtq.n == '3',2,
                                       ifelse(cmps2016$lgbtq.n == '4',3,
                                              ifelse(cmps2016$lgbtq.n == '5', 4,
                                                     ifelse(cmps2016$lgbtq.n=='6',5,NA)
                                              )))))
(cmps2016$lgbtq.1)
#rename
cmps2016$lgbtq.n<-cmps2016$lgbtq.1

#convert LGBTQ to factor so we have subgroup titles
cmps2016$lgbtq.f <- factor(cmps2016$lgbtq.1,
                           levels = c(0, 1, 2, 3, 4, 5),
                           labels = c("Heterosexual", "Gay", "Lesbian", "Bisexual", "Transgender", "Queer"))
freq(cmps2016$lgbtq.n)

#make lgbtq binary variable
cmps2016$lgbtq.dummy<-ifelse(cmps2016$lgbtq.n == '0',0,
                             ifelse(cmps2016$lgbtq.n == '1', 1,
                                    ifelse(cmps2016$lgbtq.n == '2',1,
                                           ifelse(cmps2016$lgbtq.n == '3',1,
                                                  ifelse(cmps2016$lgbtq.n == '4', 1,
                                                         ifelse(cmps2016$lgbtq.n=='5',1,NA)
                                                  )))))
freq(cmps2016$lgbtq.dummy)
cmps2016$lgbtq.dummy.f<-as.factor(cmps2016$lgbtq.dummy)
levels(cmps2016$lgbtq.dummy.f)<-c("Heterosexual","LGBTQ")
freq(cmps2016$lgbtq.dummy.f)

# variable names: 
# lgbtq.n is LGBTQ identity, numeric with other = NA
# lgbtq.f is same variable as factor, with titles
# hetero, gay, lesbian, bisexual, transgender, queer, lesbiangay are all binary variables
# lgbtq.dummy is lgbtq binary variable, where 1 = gay, lesbian, bi, trans, queer, 0 = straight

## RECODING LINKED FATE ##
freq(cmps2016$C240)
#as numeric
cmps2016$C240.n<-as.numeric(cmps2016$C240)
freq(cmps2016$C240.n)
#need to reverse direction where 4 = 0, 3 = 1, 2=2, 1=3
cmps2016$linked<- ifelse(cmps2016$C240.n == '4', 0,
                         ifelse(cmps2016$C240.n == '3', 1,
                                ifelse(cmps2016$C240.n == '2', 2,
                                       ifelse(cmps2016$C240.n == '1', 3, cmps2016$C240.n))))
freq(cmps2016$linked)
#LGBTQ linked fate 0-3 scale: cmps2016$linked where 0 = not at all, 1 = not much, 2= some, 3 = a lot

#LGBTQ linked fate 0-1 scale
cmps2016$linkedfate <-round(cmps2016$linked / 3, 2)
freq(cmps2016$linkedfate)
#$linkedfate is linked fate strength, 0-1 (0, 0.33,0.67,1)

#$linked.dummy 0 = not at all, 1 = not much, some, alot
cmps2016$linked.dummy<- ifelse(cmps2016$linked=='0',0,1)

#linked fate dummy where 0= not at all or not much, 1= some or alot
cmps2016$linked.1 <-ifelse(cmps2016$linked== '0',0,
                           ifelse(cmps2016$linked =='1', 0,1 ))

freq(cmps2016$linked.1) 

## LGBT Network ##
# Do you personally know someone who identifies as LGBT?
cmps2016$C238.n<-as.numeric(cmps2016$C238)
cmps2016$know_lgbt<-ifelse(cmps2016$C238.n == '1',1,0)
freq(cmps2016$know_lgbt)
#  know_lgbt is binary measure, 1 = yes i know someone who identifies as LGBT, 0= no

## PERCEPTIONS OF DISCRIMINATION ##
  #perception of discrim toward lgbt
freq(cmps2016$C248)
cmps2016$C248.n<-as.numeric(cmps2016$C248)
#reorder
cmps2016$discrim_lgbt3<-ifelse(cmps2016$C248.n == '1', 3,
                               ifelse(cmps2016$C248.n == '2', 2,
                                      ifelse(cmps2016$C248.n == '3',1,
                                             ifelse(cmps2016$C248.n == '4', 0,
                                                    ifelse(cmps2016$C248.n == '5', NA,NA)))))
freq(cmps2016$discrim_lgbt3) 
  #0= no discrim toward lgbt, 1= a little, 2=some, 3= alot, NA= Dont know
cmps2016$discrim_lgbt<-cmps2016$discrim_lgbt3/3

freq(cmps2016$discrim_lgbt) 
  #rescaled 0-1
  #0= no discrim toward lgbt, 0.33= a little, 0.66=some, 1.0= alot, NA= Dont know

## EXPERIENCES WITH DISCRIMINATION ##
freq(cmps2016$C255) #gender or sexuality
#convert to numeric
cmps2016$C255.n<-as.numeric(cmps2016$C255)
freq(cmps2016$C255.n)
#relevel 0/1
cmps2016$discrim_gendersexuality<-ifelse(cmps2016$C255.n == '1',1,0)
#make NAs 0. These individuals reported no discrimination.
cmps2016$discrim_gendersexuality[is.na(cmps2016$discrim_gendersexuality)]<-0

freq(cmps2016$discrim_gendersexuality) 
  # 1 = experienced discrimination because of gender or sexuality, 0 have not

## RACIAL LINKED FATE ##

freq(cmps2016$C150) #do you think what happens generally to [racial group] in this country will have...
cmps2016$C150.n<-as.numeric(cmps2016$C150)
freq(cmps2016$C150.n)
cmps2016$racelinked_yn<-ifelse(cmps2016$C150.n == '2',0,1)
freq(cmps2016$racelinked_yn) # 0 are people who said no. 1 said yes.

freq(cmps2016$C151) #follow up for strength
cmps2016$C151.n<-as.numeric(cmps2016$C151)
freq(cmps2016$C151.n) #now need to make NAs 0 in ordr to combine
cmps2016$C151.n[is.na(cmps2016$C151.n)]<-0
freq(cmps2016$C151.n)
#create new var combining these two. 0 = not at all. 1 = not very. 2= some. 3=alot
cmps2016$racelinked<-ifelse(cmps2016$racelinked_yn==0,0,
                            ifelse(cmps2016$C151.n==3,1,
                                   ifelse(cmps2016$C151.n==2,2,
                                          ifelse(cmps2016$C151.n==1,3,
                                                 ifelse(cmps2016$C151.n==0,NA,0)))))
freq(cmps2016$racelinked)

cmps2016$racelinked1<-cmps2016$racelinked/3
freq(cmps2016$racelinked1) # - = not at all, .33 = not very, .66 = some, 1= alot.

## DEMOGRAPHICS RECODING ##

#Gender
freq(cmps2016$S3)
cmps2016$S3.n<-as.numeric(cmps2016$S3)
freq(cmps2016$S3.n)

#male binary
cmps2016$male<-ifelse(cmps2016$S3.n == '2',1,0)
table(cmps2016$male)

#female binary
cmps2016$female<-ifelse(cmps2016$S3.n == '1',1,0)
freq(cmps2016$female)

#AGE
freq(cmps2016$AGE)
#duplicate bc capital is annoying
cmps2016$age<-cmps2016$AGE
freq(cmps2016$age)

#Race
#white binary
cmps2016$white<-cmps2016$S2_1
freq(cmps2016$white)
cmps2016$white1<-cmps2016$white
#latino binary 
cmps2016$latino<-cmps2016$S2_2
table(cmps2016$latino)
#black binary
cmps2016$black<-cmps2016$S2_3
table(cmps2016$black)
#Asian binary
cmps2016$asian<-cmps2016$S2_4
table(cmps2016$asian)

#combined race variable 
cmps2016$ETHNIC_QUOTA.n<-as.numeric(cmps2016$ETHNIC_QUOTA)
freq(cmps2016$ETHNIC_QUOTA.n)
cmps2016$race<-as.factor(cmps2016$ETHNIC_QUOTA.n)
levels(cmps2016$race)<-c("White","Latino","Black","Asian")
table(cmps2016$race)
freq(cmps2016$race)

#nonwhite binary variable
cmps2016$nonwhite<-ifelse(cmps2016$ETHNIC_QUOTA.n == '1',0,1)
freq(cmps2016$nonwhite)

#Education
freq(cmps2016$C381)
cmps2016$C381.n<-as.numeric(cmps2016$C381)
#rescale 0-1
cmps2016$educ<-cmps2016$C381.n/6
freq(cmps2016$educ)
  # educ 0.16= Middle school or less, 0.33=Some HS, 0.5 = HS Grad/GED, 0.66 = Some College, 0.83 = 4-year college Graduate, 1=Post-Graduate Education

#Income - income.1 is numeric variable, where 12=over 200k income. I want to combine this with the C384 variable, which forces the NAs to make a choice
freq(cmps2016$C383)
freq(cmps2016$C384)
cmps2016$C383.n<-as.numeric(cmps2016$C383)
cmps2016$C384.n<-as.numeric(cmps2016$C384)
cmps2016$income.1<- ifelse(cmps2016$C383.n == '13', NA, cmps2016$C383.n)
freq(cmps2016$income.1)
freq(cmps2016$C384.n)
#break income into quartiles
cmps2016$income.4<-cut2(cmps2016$income.1,g=4)
freq(cmps2016$income.4)  # in this var, 1-2,3-5,6-8,9-12
#so, <29,999, (30-59,999), (60-89,999), >90k
#C384 is coded diff, <40, 40-79,999, >80k

#breaking income into 5 categories in order to accomodate the way the 2 income variables are measured.
cmps2016$income.5 <- ifelse(cmps2016$income.1 == '1', 1,
                            ifelse(cmps2016$income.1 == '2', 2,
                                   ifelse(cmps2016$income.1 == '3', 2,
                                          ifelse(cmps2016$income.1 == '4', 3,
                                                 ifelse(cmps2016$income.1 == '5', 3,
                                                        ifelse(cmps2016$income.1 == '6', 3,
                                                               ifelse(cmps2016$income.1 == '7', 3,
                                                                      ifelse(cmps2016$income.1 == '8', 4,
                                                                             ifelse(cmps2016$income.1 == '9', 4,
                                                                                    ifelse(cmps2016$income.1 == '10', 5,
                                                                                           ifelse(cmps2016$income.1 == '11', 5,
                                                                                                  ifelse(cmps2016$income.1 == '12', 5, NA))))))))))))

freq(cmps2016$income.5) # 1: <20k, 2: 20K - 40K, 3:40- 79,999 , 4:80-100, 5: >100k

#duplicate 
cmps2016$income.na0<-cmps2016$income.5
#make NAs 0
cmps2016$income.na0[is.na(cmps2016$income.na0)]=0
freq(cmps2016$income.na0)
#duplicate
cmps2016$C384.n1<-cmps2016$C384.n
cmps2016$C384.n1[is.na(cmps2016$C384.n1)]=0
freq(cmps2016$C384.n1)

#need to make NAs = 0 in order to combine variable.
cmps2016$newincome <- ifelse(cmps2016$income.na0 == 1, 1,
                             ifelse(cmps2016$income.na0 == 2 | cmps2016$C384.n1 == 1, 2,
                                    ifelse(cmps2016$income.na0 == 3 | cmps2016$C384.n1 == 2, 3,
                                           ifelse(cmps2016$income.na0 == 4 | cmps2016$C384.n1 == 3, 4,
                                                  ifelse(cmps2016$income.na0 == 5, 5,
                                                         ifelse(cmps2016$income.na0== 0 | cmps2016$C384.n1==0, NA,0))))))
freq(cmps2016$newincome) 
#newincome is a 5- level measure of annual income.
# 1: <20k, 2: 20K - 40K, 3:40- 79,999 , 4:80-100, 5: >100k

#rescale 0-1
cmps2016$income<-cmps2016$newincome/5
freq(cmps2016$income)
# 0.2: <20k, 0.4: 20K - 40K, 0.6:40- 79,999 , 0.8:80-100, 1: >100k

## PARTICIPATION AND POLITICS VARIABLES ## 
# Political Interest
freq(cmps2016$C33)
cmps2016$C33.n<-as.numeric(cmps2016$C33)
freq(cmps2016$C33.n)

#reverse direction
cmps2016$polinterest.1<-ifelse(cmps2016$C33.n == '4',0,
                               ifelse(cmps2016$C33.n =='3',1,
                                      ifelse(cmps2016$C33.n =='2',2,
                                             ifelse(cmps2016$C33.n =='1',3,NA))))

freq(cmps2016$polinterest.1)# Interest in politics
  # 0 = not at all interested
  # 1 = not that interested
  # 2 = somewhat interested
  # 3 = very interested

#rescale 0-1
cmps2016$polinterest<-cmps2016$polinterest.1/3
freq(cmps2016$polinterest)
  # 0 = not at all interested
  # 0.33  = not that interested
  # 0.66  = somewhat interested
  # 1  = very interested

## PARTY IDENTIFICATION ##
# 3 level party ID
freq(cmps2016$C25)
levels(cmps2016$C25)<-c("Republican","Democrat","Independent","Other")
cmps2016$PID<-cmps2016$C25
freq(cmps2016$PID)
cmps2016$C25.n<-as.numeric(cmps2016$C25)
freq(cmps2016$C25.n)# $PID 1= R, 2=D,3=I,4=Other

#Combine Independent and other
cmps2016$C25.n1<-ifelse(cmps2016$C25.n== '4',3, cmps2016$C25.n)
freq(cmps2016$C25.n1) # 1=Rep , 2= Dem, 3=Ind/Other.

# c26 is strength variable
freq(cmps2016$C26)
#convert to numeric
cmps2016$C26.n<-as.numeric(cmps2016$C26)
freq(cmps2016$C26.n)

#make NAs be 0
cmps2016$C26.n1<-cmps2016$C26.n
freq(cmps2016$C26.n1)
cmps2016$C26.n1[is.na(cmps2016$C26.n1)]=0
freq(cmps2016$C26.n1)
#now, 0 = People who selected independent, other, dont know for party question.
#1= strong, 2= weak.

# C27 is force choice.
freq(cmps2016$C27)
cmps2016$C27.n<-as.numeric(cmps2016$C27)
freq(cmps2016$C27.n) #1 = rep, 2= dem, 3=ind, 4=other, 5=dont know
#i need to merge independents with other
#first make dont know's = NA
cmps2016$C27.n1<-ifelse(cmps2016$C27.n == '1',1,
                        ifelse(cmps2016$C27.n =='2',2,
                               ifelse(cmps2016$C27.n=='3',3,
                                      ifelse(cmps2016$C27.n=='4',3,
                                             ifelse(cmps2016$C27.n=='5',NA,0)))))
freq(cmps2016$C27.n1)
# 1 = lean rep, 2= lean dem, 3=lean ind/other, NA= Dont know

#Now, duplicate variable and make NAs 0. 
cmps2016$C27.n2<-cmps2016$C27.n1
cmps2016$C27.n2[is.na(cmps2016$C27.n2)]=0
freq(cmps2016$C27.n2)


cmps2016$pid7<-ifelse(cmps2016$C25.n1=='1' & cmps2016$C26.n1 == '1',7,
                      ifelse(cmps2016$C25.n1 =='1' & cmps2016$C26.n1 == '2',6,
                             ifelse(cmps2016$C27.n2 == '1',5,
                                    ifelse(cmps2016$C25.n1 == '3' & cmps2016$C27.n2=='3',4,
                                           ifelse(cmps2016$C27.n2== '2',3,
                                                  ifelse(cmps2016$C25.n1== '2' & cmps2016$C26.n1 == '2', 2,
                                                         ifelse(cmps2016$C25.n1 == '2' & cmps2016$C26.n1 == '1', 1, NA)))))))
freq(cmps2016$pid7)
#$pid7 is the 7-point party ID where:
# 1 = Strong Democrat
# 2 = Weak Democrat
# 3 = Ind/Lean Dem
# 4 = Independent
# 5 = Ind/Lean Rep
# 6 = Weak Republican
# 7 = Strong Republican
# NA = Don't Knows

# Convert recoded pid7 variable to factor for future use
cmps2016$pid7.f <- recode(cmps2016$pid7, 
                          "1" = "1 - Strong Democrat",
                          "2" = "2 - Weak Democrat",
                          "3" = "3 - Ind/Lean Dem",
                          "4" = "4 - Independent",
                          "5" = "5 - Ind/Lean Rep",
                          "6" = "6 - Weak Republican",
                          "7" = "7 - Strong Republican")

cmps2016$pid7.f <- factor(cmps2016$pid7.f)
freq(cmps2016$pid7.f)

#rescale 0-1
cmps2016$pid_scale<-cmps2016$pid7/7
freq(cmps2016$pid_scale) #higher values -> more republican
# 0.14 = Strong Democrat
# 0.28 = Weak Democrat
# 0.42 = Ind/Lean Dem
# 0.57 = Independent
# 0.71 = Ind/Lean Rep
# 0.85 = Weak Republican
# 1 = Strong Republican
# NA = Don't Knows

# Partisanship Dummy Variables # 
#democratic dummy variable, 1 = dem 0 = rep, ind, other
cmps2016$dem<-ifelse(cmps2016$C25.n == '2',1,0)
freq(cmps2016$dem)
#republican dummy variable, 1 = rep, 0 = dem, ind, other.
cmps2016$rep<-ifelse(cmps2016$C25.n == '1', 1, 0)
freq(cmps2016$rep)
#independent dummy variable, 1 = ind, 0=dem, rep, other
cmps2016$ind<-ifelse(cmps2016$C25.n =='3',1,0)
freq(cmps2016$ind)
#independent dummy variable, 1 = ind / other, 0 = dem/rep
cmps2016$indother<-ifelse(cmps2016$C25.n == '3',1,
                          ifelse(cmps2016$C25.n=='4',1,0))
freq(cmps2016$indother)

# Ideology #
freq(cmps2016$C31) 
cmps2016$C31.n<-as.numeric(cmps2016$C31)
freq(cmps2016$C31.n)# 1 very liberal, 5 very conservative, 6= 'none of these'
#make 'none of these' responses NA
cmps2016$ideology5<- ifelse(cmps2016$C31.n == '6', NA, cmps2016$C31.n)
freq(cmps2016$ideology5) 
# Ideology - 1=very liberal
# 2 = somewhat liberal
# 3 = moderate
# 4 = somewhat conservative
# 5 = very conservative 
# NA = 'none of these'

#rescale 0-1
cmps2016$ideology<-cmps2016$ideology5/5
freq(cmps2016$ideology)
# Ideology - 0.2=very liberal
# 0.4 = somewhat liberal
# 0.6 = moderate
# 0.8 = somewhat conservative
# 1.0 = very conservative 
# NA = 'none of these'

## Political Behavior ##

#voter registration
freq(cmps2016$S5)
cmps2016$S5.n<-as.numeric(cmps2016$S5)
freq(cmps2016$S5.n)
cmps2016$votereg<-ifelse(cmps2016$S5.n == 1,1,0)
freq(cmps2016$votereg)

#voting
freq(cmps2016$C12)
cmps2016$C12.n<-as.numeric(cmps2016$C12)
freq(cmps2016$C12.n)

cmps2016$vote2016<-ifelse(cmps2016$C12.n == '1', 1,
                          ifelse(cmps2016$C12.n =='2',0, NA))
cmps2016$vote2016[is.na(cmps2016$vote2016)]<-0
#voting dummy is $vote2016. NAs (unregistered) have been assigned 0
freq(cmps2016$vote2016)

#voting in state and local elections
freq(cmps2016$C32)
cmps2016$C32.n<-as.numeric(cmps2016$C32)
freq(cmps2016$C32.n)
#relevel 0-3 instead of 1-4
cmps2016$C32.n1<-cmps2016$C32.n-1
freq(cmps2016$C32.n1)
#relevel 0-1 instead of 0-3
cmps2016$vote_statelocal<-cmps2016$C32.n1/3

freq(cmps2016$vote_statelocal) # 0 = never vote in state/local election,
# 0.33 = occasionally vote, 0.66 = vote in many, 1 = vote in every single

cmps2016$vote_statelocal_1<-ifelse(cmps2016$vote_statelocal=='0',0,1)
freq(cmps2016$vote_statelocal_1)
  # dummy where 0 = never vote state local, 1 = occasionally to always vote in state  /local

# participation - non voting
# for each, converting to numeric and releveling as 0/1 instead of 1/2
freq(cmps2016$C56) # discussed politics with friends/fam
cmps2016$C56.n<-as.numeric(cmps2016$C56)
freq(cmps2016$C56.n)
cmps2016$discuss<-ifelse(cmps2016$C56.n == 1,1,0)
freq(cmps2016$discuss)

freq(cmps2016$C57) #worked for candidate/party
cmps2016$C57.n<-as.numeric(cmps2016$C57)
freq(cmps2016$C57.n)
cmps2016$volunteer<-ifelse(cmps2016$C57.n==1,1,0)
freq(cmps2016$volunteer)

freq(cmps2016$C58) #contributed money
cmps2016$C58.n<-as.numeric(cmps2016$C58)
freq(cmps2016$C58.n)
cmps2016$donate<-ifelse(cmps2016$C58.n ==1,1,0)
freq(cmps2016$donate) 

freq(cmps2016$C59) # wore campaign button, posted sign, sticker
cmps2016$C59.n<-as.numeric(cmps2016$C59)
freq(cmps2016$C59.n)
cmps2016$display<-ifelse(cmps2016$C59.n ==1,1,0)
freq(cmps2016$display)

freq(cmps2016$C60) #contacted electeds
cmps2016$C60.n<-as.numeric(cmps2016$C60)
freq(cmps2016$C60.n)
cmps2016$contact<-ifelse(cmps2016$C60.n ==1,1,0)
freq(cmps2016$contact)

freq(cmps2016$C64) #discussed candidate/politics on social media
cmps2016$C64.n<-as.numeric(cmps2016$C64)
freq(cmps2016$C64.n)
cmps2016$online<-ifelse(cmps2016$C64.n ==1,1,0)
freq(cmps2016$online)

freq(cmps2016$C66) #attended protest/march/rally
cmps2016$C66.n<-as.numeric(cmps2016$C66)
freq(cmps2016$C66.n)
cmps2016$protest<-ifelse(cmps2016$C66.n ==1,1,0)
freq(cmps2016$protest)

freq(cmps2016$C67) #signed petititon 
cmps2016$C67.n<-as.numeric(cmps2016$C67)
freq(cmps2016$C67.n)
cmps2016$petition<-ifelse(cmps2016$C67.n ==1,1,0)
freq(cmps2016$petition)

freq(cmps2016$C68) #boycotted company for political reasons
cmps2016$C68.n<-as.numeric(cmps2016$C68)
freq(cmps2016$C68.n)
cmps2016$boycott<-ifelse(cmps2016$C68.n ==1,1,0)
freq(cmps2016$boycott)

freq(cmps2016$C62) #worked or cooperated with ppl in community to solve problems
cmps2016$C62.n<-as.numeric(cmps2016$C62)
freq(cmps2016$C62.n)
cmps2016$community<-ifelse(cmps2016$C62.n==1,1,0)
freq(cmps2016$community)

freq(cmps2016$C63) #attend meeting to discuss issues in commmunity
cmps2016$C63.n<-as.numeric(cmps2016$C63)
freq(cmps2016$C63.n)
cmps2016$meeting<-ifelse(cmps2016$C63.n==1,1,0)
freq(cmps2016$meeting)

# create combined measure of discussing politics
freq(cmps2016$discuss) #with fam and friends
freq(cmps2016$online) #discuss pol online
#create index
cmps2016$discuss1<-cmps2016$discuss+cmps2016$online
#rescale
cmps2016$discusspol<-cmps2016$discuss1/2
# 0 = never, 0.5 = some pol discussion 1 = alot
freq(cmps2016$discusspol)

## POLITICAL PARTICIPATION INDEX ##
# based on verba schlozman brady 1995 participation measure
# voting, contact official, donate to campaign, worked to solve local issue, 
# volunteer for campaign/display campaign sign, protest,attend meeting
cmps2016$partic_all7<-cmps2016$vote2016+cmps2016$contact+cmps2016$community+cmps2016$volunteer+cmps2016$donate+cmps2016$protest+cmps2016$meeting
freq(cmps2016$partic_all7) # ranging 0 - 7. 0 = no participation, 7 = all types of participation.
cmps2016$partic_all<-cmps2016$partic_all7/7
freq(cmps2016$partic_all) #participation scale, 0-1

#Social, cultural, civic, political group, union involvement
freq(cmps2016$C53) #are you part of one?
cmps2016$C53.n<-as.numeric(cmps2016$C53)
freq(cmps2016$C53.n)
cmps2016$C53.n1<-ifelse(cmps2016$C53.n == '3',0,cmps2016$C53.n)
freq(cmps2016$C53.n1) # 0 = none, 1= one group, 2= more than one group


freq(cmps2016$C54) #do you regularly attend?
cmps2016$C54.n<-as.numeric(cmps2016$C54)
freq(cmps2016$C54.n) #NAs in this are people who said no to C53. Need to make them 0 for new var
cmps2016$C54.n[is.na(cmps2016$C54.n)]<-0
freq(cmps2016$C54.n)

cmps2016$groups<-ifelse(cmps2016$C53.n1==0,0,
                        ifelse(cmps2016$C53.n1 == 1 & cmps2016$C54.n ==2, 1,
                               ifelse(cmps2016$C53.n1 ==2 & cmps2016$C54.n==2,2,
                                      ifelse(cmps2016$C53.n1==1 & cmps2016$C54.n==1,3,
                                             ifelse(cmps2016$C53.n1==2 & cmps2016$C54.n ==1,4,NA)))))
freq(cmps2016$groups) # 0 = no involvement. 1=  invovled in 1 group, dont attend meeting.
# 2= involved in more than one, dont attend. 3 = involved in one, attend. 4= involved in more than one, attend.
# rescale 0-1
cmps2016$groupinvolve<-cmps2016$groups/4
freq(cmps2016$groupinvolve) # 0 = no involvement. 0.25=  invovled in 1 group, dont attend meeting.
# 0.5= involved in more than one, dont attend. 0.75 = involved in one, attend. 1.0= involved in more than one, attend.

freq(cmps2016$partic_all) #participation scale, 0-1

## POLITICAL ATTITUDES ## 
#Trust in Goverment: How much of the time do you trust federal/local govt to do what is right?
freq(cmps2016$C47) #federal
cmps2016$C47.n<-as.numeric(cmps2016$C47)

cmps2016$C47.n1<-ifelse(cmps2016$C47.n == '1', 3,
                        ifelse(cmps2016$C47.n == '2', 2,
                               ifelse(cmps2016$C47.n == '3',1,
                                      ifelse(cmps2016$C47.n == '4', 0,NA))))
freq(cmps2016$C47.n1)
cmps2016$trust_fedgovt<-cmps2016$C47.n1/3
freq(cmps2016$trust_fedgovt) # 0 = never trust fed govt, 1= just about always
#
freq(cmps2016$C48) #local
cmps2016$C48.n<-as.numeric(cmps2016$C48)

cmps2016$C48.n1<-ifelse(cmps2016$C48.n == '1', 3,
                        ifelse(cmps2016$C48.n == '2', 2,
                               ifelse(cmps2016$C48.n == '3',1,
                                      ifelse(cmps2016$C48.n == '4', 0,NA))))
freq(cmps2016$C48.n1)
cmps2016$trust_localgovt<-cmps2016$C48.n1/3
freq(cmps2016$trust_localgovt) # 0 = never trust local govt 1=just about always

#trust index
cmps2016$trust_local_fed<-cmps2016$trust_fedgovt+cmps2016$trust_localgovt
cmps2016$trust_govt<-cmps2016$trust_local_fed/2

freq(cmps2016$trust_govt) #trust that government (federal and local) will do what is right.
#0= never 1= just about always

# Policy Support
freq(cmps2016$C40) #ban same sex marriage. need to be careful with this one, this is coded so that higher scores are more conservative. the other policies are higher scores, more liberal. recode this to make strongly 
cmps2016$C40.n<-as.numeric(cmps2016$C40)
freq(cmps2016$C40.n) 
cmps2016$C40.n1<-cmps2016$C40.n-1
cmps2016$samesexmarriage<-cmps2016$C40.n1/4
freq(cmps2016$samesexmarriage) #0 = strongly agree, should pass amendment to ban same sex marriage, .25 = agree, .5=neither agree nor disagree, .75= disagree to ban, 1= strongly disagree to ban. aka higher scores, more supportive. 
#

# climate
freq(cmps2016$C42) #fed should pass laws to combat effects of climate change
cmps2016$C42.n<-as.numeric(cmps2016$C42)
freq(cmps2016$C42.n)
cmps2016$C42.n1<-ifelse(cmps2016$C42.n =='5',0,
                        ifelse(cmps2016$C42.n =='4',1,
                               ifelse(cmps2016$C42.n =='3',2,
                                      ifelse(cmps2016$C42.n =='2',3,
                                             ifelse(cmps2016$C42.n =='1',4,NA)))))
freq(cmps2016$C42.n1)
cmps2016$climate<-cmps2016$C42.n1/4
freq(cmps2016$climate) # 0 = govt should not pass laws to combat effects, 1 = strongly agree should pass
#

# tax cut for middle class, wealthy pay more
freq(cmps2016$C43)
cmps2016$C43.n<-as.numeric(cmps2016$C43)
freq(cmps2016$C43.n)
cmps2016$C43.n1<-ifelse(cmps2016$C43.n =='5',0,
                        ifelse(cmps2016$C43.n =='4',1,
                               ifelse(cmps2016$C43.n =='3',2,
                                      ifelse(cmps2016$C43.n =='2',3,
                                             ifelse(cmps2016$C43.n =='1',4,NA)))))
freq(cmps2016$C43.n1)
cmps2016$taxes<-cmps2016$C43.n1/4
freq(cmps2016$taxes) # 0 - strongly disagree that middle class should get tax cut, 1= strongly agree.
#
#Affordable care act. Health care reform law should be amended and improved, not repealed.
freq(cmps2016$C45)
cmps2016$C45.n<-as.numeric(cmps2016$C45)
freq(cmps2016$C45.n)
cmps2016$C45.n1<-ifelse(cmps2016$C45.n =='5',0,
                        ifelse(cmps2016$C45.n =='4',1,
                               ifelse(cmps2016$C45.n =='3',2,
                                      ifelse(cmps2016$C45.n =='2',3,
                                             ifelse(cmps2016$C45.n =='1',4,NA)))))
freq(cmps2016$C45.n1)
cmps2016$aca<-cmps2016$C45.n1/4
freq(cmps2016$aca) # 0 = repeal obama care 1=amend and improve
#
#policy index
cmps2016$policyindex4<-cmps2016$samesexmarriage+cmps2016$climate+cmps2016$taxes+cmps2016$aca
freq(cmps2016$policyindex4)
cmps2016$policyindex<-cmps2016$policyindex4/4
freq(cmps2016$policyindex) #index where 0 = least supportive of these policies, 1= most supportive.
#

#filter dataset to only have LGBTQ respondents
cmps2016$lgbtq.only<-ifelse(cmps2016$lgbtq.n == '0',NA, cmps2016$lgbtq.n)
lgbt_data<-cmps2016 %>% filter(!is.na(lgbtq.only))
freq(lgbt_data$lgbtq.only)
View(lgbt_data)
#filter dataset to only have straight respodnents
straight_data <- subset(cmps2016, hetero == 1)
View(straight_data)
#filter dataset to only have nonwhite respondents
cmps2016$nonwhite<-ifelse(cmps2016$ETHNIC_QUOTA.n == '1',0,1)
nonwhite_data<-cmps2016%>%filter(nonwhite==1)

#########
## REGRESSION MODELS ##
#LGBTQ Sample
#participation index lgbt
particlm6_lgbt.w<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white1+age+female,data=lgbt_data, weights=WEIGHT)
summary(particlm6_lgbt.w)
#vote reg lgbt
votereg.lgbt.all.w<-lm(votereg ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data,weights=WEIGHT)
summary(votereg.lgbt.all.w)
d1<-votereg.lgbt.all.w
#vote 2016 
vote.lgbt.all<-lm(vote2016~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white1+age+female,data=lgbt_data, weights = WEIGHT)
summary(vote.lgbt.all)
d2<-vote.lgbt.all
#protesting 
protest.lgbt.all<-lm(protest~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white1+age+female,data=lgbt_data, weights = WEIGHT)
summary(protest.lgbt.all)
d3<-protest.lgbt.all
#contact officials
contact.lgbt.all.w <- lm(contact ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data,weights = WEIGHT)
summary(contact.lgbt.all.w)
d4<-contact.lgbt.all.w
#donating
donate.lgbt.all.w <- lm(donate ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology + white1 + age + female, data = lgbt_data,weights = WEIGHT)
summary(donate.lgbt.all.w)
d5<-donate.lgbt.all.w
#discussion
discuss.lgbt.all.w <- lm(discusspol ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data,weights=WEIGHT)
summary(discuss.lgbt.all.w)
d7<-discuss.lgbt.all.w
#community organize
community.lgbt.all.w<-lm(community ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data,weights=WEIGHT)
summary(community.lgbt.all.w)
d8<-community.lgbt.all.w
#boycott
boycott.lgbt.all.w<-lm(boycott ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data,weights=WEIGHT)
summary(boycott.lgbt.all.w)
d9<-boycott.lgbt.all.w
#social and political group involvement
group.lm3.lgbt<-lm(groupinvolve ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data)
summary(group.lm3.lgbt)
d6<-group.lm3.lgbt
#social and pol group WITH WEIGHTS
group.lgbt.all.w<-lm(groupinvolve ~ linkedfate + income + educ + polinterest.1 + pid_scale + ideology  + white1 + age + female, data = lgbt_data,weights=WEIGHT)
summary(group.lgbt.all.w)
d10<-group.lgbt.all.w

# participation index - lgbt linked
particlm3_lgbt.w<-lm(partic_all~linkedfate,data=lgbt_data, weights=WEIGHT)
summary(particlm3_lgbt.w)
s4<-particlm3_lgbt.w
# participation index - + theory partic links
particlm4_lgbt.w<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology,data=lgbt_data, weights=WEIGHT)
summary(particlm4_lgbt.w)
s5<-particlm4_lgbt.w

lgbt_data$white1<-lgbt_data$white
# + everything
particlm6_lgbt.w<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white1+age+female,data=lgbt_data, weights=WEIGHT)
summary(particlm6_lgbt.w)
s6<-particlm6_lgbt.w
#Full Sample
# participation index - lgbt linked with weight
particlm3.w<-lm(partic_all~linkedfate,data=cmps2016,weights = WEIGHT)
summary(particlm3.w)
s1<-particlm3.w
# participation index - + theory partic links
particlm4.w<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology,data=cmps2016,weights = WEIGHT)
summary(particlm4.w)
s2<-particlm4.w
# + everything
particlm6.w<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white1+age+female,data=cmps2016,weights = WEIGHT)
summary(particlm6.w)
s3<-particlm6.w
#Straight Sample
#participation index, straight sample
particlm_straight<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white+age+female,data= straight_data)
summary(particlm_straight)

straight_data$white1<-straight_data$white
#participation index, straight sample WITH WEIGHTS
particlm_straight.w<-lm(partic_all~linkedfate+income+educ+polinterest.1+pid_scale+ideology+white1+age+female,data= straight_data,weights=WEIGHT)
summary(particlm_straight.w)
s7<-particlm_straight.w



##########
#TABLE 1 - Mean Linked Fate by Identities
#Table was created in Latex. Latex code provided in .tex file

##Queer linked fate by LGBTQ Identities
aggregate(lgbt_data$linkedfate,list(lgbt_data$lgbtq.f),FUN=mean,na.rm=T)
lfbylgbtqid <- aggregate(linkedfate ~ lgbtq.f, data = lgbt_data,
                           FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                               sd = sd(x, na.rm = TRUE)))
counts <- table(lgbt_data$lgbtq.f)
#Merge counts with aggregated data
lfbylgbtqid$counts <- counts[lfbylgbtqid$lgbtq.f]
#Results
print(lfbylgbtqid)

##Queer Linked fate by Racial Identities
aggregate(lgbt_data$linkedfate,list(lgbt_data$race),FUN=mean,na.rm=T)
lfbyracialid <- aggregate(linkedfate ~ race, data = lgbt_data,
                         FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                             sd = sd(x, na.rm = TRUE)))
counts <- table(lgbt_data$race)

lfbyracialid$counts <- counts[lfbyracialid$race]
#Results
print(lfbyracialid)

##Queer Linked fate by Party ID
lfbypid <- aggregate(linkedfate ~ C25.n1, data = lgbt_data,
                             FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                                 sd = sd(x, na.rm = TRUE)))
counts<-table(lgbt_data$C25.n1)
lfbypid$counts<-counts[lfbypid$C25.n1]

#results
print(lfbypid) #where 1 = republican, 2=democrat, 3=ind/other

##Disaggregate bisexual by gender - Reviewer request
#make Bisexual women variable
freq(lgbt_data$female)
freq(lgbt_data$bisexual)
lgbt_data$biwomen<-ifelse(lgbt_data$bisexual =='1' & lgbt_data$female== '1',1,0)
freq(lgbt_data$biwomen)

biwomen_summary <- aggregate(linkedfate ~ biwomen, data = lgbt_data,
                             FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                                 sd = sd(x, na.rm = TRUE)))
biwomen_summary
# Bi women n = 331 linkedfate mean = 0.611 sd = 0.346

#make Bisexual men variable
lgbt_data$bimen<-ifelse(lgbt_data$bisexual =='1' & lgbt_data$male== '1',1,0)
freq(lgbt_data$bimen)

bimen_summary <- aggregate(linkedfate ~ bimen, data = lgbt_data,
                           FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                               sd = sd(x, na.rm = TRUE)))
bimen_summary
# Bi men n = 83 linkedfate mean = 0.574 sd=323

##########
#FIGURE 1 - Queer Linked Fate and Political Participation

partic_fig <- plot_models(particlm6_lgbt.w, vote.lgbt.all, protest.lgbt.all,
                   p.threshold = c(0.05, 0.01, 0.001),
                   m.labels = c("Participation Index", "2016 Vote", "Protest"),
                   show.p = TRUE,
                   axis.labels = c("Queer Linked Fate"),
                   spacing = 2,
                   grid=T,
                   show.legend=F,
                   colors = c("black"),
                   rm.terms = c("income", "educ", "polinterest.1", "pid_scale", "ideology", "white1", "age", "female"),
                   wrap.title = 60,
                   title = "Fig 1: Queer Linked Fate and Political Participation")
partic_fig_final <- partic_fig +
  geom_hline(yintercept = 0, color = "red", size = 0.15) +
  ylim(-0.10,0.26)+
  set_theme(title.size = 1.15)+
  labs(caption="CMPS 2016 ACS sample weights used. Models include controls.")
theme(plot.title=element_text(hjust = 0.4))

ggsave("partic_fig_final.tiff")
ggsave("partic_fig_final.tiff", plot = partic_fig_final, 
       width = 8, height = 6, dpi = 300, units = "in")

ggsave("partic_fig_final.pdf")

###########
#FIGURE 2 - Queer Linked Fate by Identities
#model - linked fate by identities, with conttrols
table2lm<-lm(linkedfate~gay+lesbian+bisexual+transgender+queer+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white1,data=cmps2016, weights = WEIGHT)
summary(table2lm)

newracelm<-lm(linkedfate~black+latino+asian+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female,data=lgbt_data,weights = WEIGHT)
summary(newracelm)

lfbyid<-plot_models(table2lm,newracelm,
                    p.threshold = c(0.05, 0.01, 0.001),
                    rm.terms=c("discrim_lgbt","discrim_gendersexuality","know_lgbt",
                               "pid_scale","ideology","polinterest.1","age","income","educ","female","white1"),
                    show.p=T,
                    colors = "black",
                    show.legend=F,
                    title="Fig 2: Queer Linked Fate by Identities",
                    axis.labels=c("Asian LGBTQ", "Latino LGBTQ","Black LGBTQ", "Other Queer ID","Transgender","Bisexual","Lesbian","Gay"))

lfbyid.1<-lfbyid+
  geom_hline(yintercept = 0, color = "red", size = 0.15) +
  ylim(-0.25,0.5)+
  labs(caption="CMPS 2016 ACS sample weights used. Model includes controls.")+
  theme(plot.title=element_text(hjust = 0.5))

ggsave("lfbyid_plot.tiff", plot = lfbyid.1, 
       width = 9, height = 6, dpi = 300, units = "in")

##########
## Appendix B: Sample Characteristics ##
#Table A2

#age
#mean age and n, lgbt sample
freq(lgbt_data$age)
summary(lgbt_data$age,na.rm=T)
sum(!is.na(lgbt_data$age))
#mean age and n , straight sample
freq(straight_data$age)
summary(straight_data$age, na.rm=T)
sum(!is.na(straight_data$age))
#mean age and n, full sample
summary(cmps2016$age, na.rm=T)
sum(!is.na(cmps2016$age))

#educ
#mean educ and n, lgbt sample
freq(lgbt_data$educ)
summary(lgbt_data$educ,na.rm=T)
sum(!is.na(lgbt_data$educ))
#mean educ and n, straight sample
summary(straight_data$educ)
sum(!is.na(straight_data$educ))
#mean educ and n, full sample
summary(cmps2016$educ)
sum(!is.na(cmps2016$educ))

#income
# 0.2: <20k, 0.4: 20K - 40K, 0.6:40- 79,999 , 0.8:80-100, 1: >100k
#mean income and n, lgbt sample
summary(lgbt_data$income)
sum(!is.na(lgbt_data$income))
#mean income and n, straight sample
summary(straight_data$income)
sum(!is.na(straight_data$income))
#mean income and n, full sample
summary(cmps2016$income)
sum(!is.na(cmps2016$income))

#gender
freq(lgbt_data$S3.n) #in lgbt sample, 319 men, 544 women
freq(straight_data$S3.n) #in straight sample, 3141 men, 5970 women
freq(cmps2016$S3.n) #in full sample, 3514 men, 6612 women

#race
freq(lgbt_data$race) #lgbt sample - 77 white, 337 latino, 255 blac, 206 asian
freq(straight_data$race) #straight sample - 945 white, 2610 latino, 2803 black, 2757 asian
freq(cmps2016$race) #full sample - 1034 white, 3002 latino, 3102 black, 3006 asian

#party ID
freq(lgbt_data$PID) #lgbt sample - 447 dem, 95 rep, 245 ind, 88 other
freq(straight_data$PID) #straight sample - 4630 dem, 1398 rep, 2514 ind, 573 other
freq(cmps2016$PID) #full sample - 5128 dem, 1515 rep, 2814 ind, 687 other

#ideology - 0.2=very liberal, 0.4 = somewhat liberal, 0.6 = moderate, 0.8 = somewhat conservative, 1.0 = very conservative, NA = 'none of these'

#lgbt sample ideology
freq(lgbt_data$ideology)
summary(lgbt_data$ideology)
sum(!is.na(lgbt_data$ideology))
#straight sample ideology
freq(straight_data$ideology)
summary(straight_data$ideology)
sum(!is.na(straight_data$ideology))
#full sample ideology
freq(cmps2016$ideology)
summary(cmps2016$ideology)
sum(!is.na(cmps2016$ideology))


## Appendix D Analysis: Racial v. Queer Linked Fate, By Race ##
#Table A3
#mean lgbtq linked fate by racial id, straight people
racelgbtlf_straight <- aggregate(linkedfate ~ race, data = straight_data,
                              FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                                  sd = sd(x, na.rm = TRUE)))
print(racelgbtlf_straight)
# mean lgbtq linked fate by racial id, lgbtq people
racelgbtlf_lgbtq <- aggregate(linkedfate ~ race, data = lgbt_data,
                        FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                            sd = sd(x, na.rm = TRUE)))

#mean racial linked fate by racial id, straight people
raciallfbyracial_straight <- aggregate(racelinked1 ~ race, data = straight_data,
                        FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                            sd = sd(x, na.rm = TRUE)))
print(raciallfbyracial_straight)
#mean racial linked fate by racial id, queer people
raciallfbyracial_lgbtq <- aggregate(racelinked1 ~ race, data = lgbt_data,
                              FUN = function(x) c(mean = mean(x, na.rm = TRUE),
                                                  sd = sd(x, na.rm = TRUE)))
print(raciallfbyracial_lgbtq)

## Appendix E Analysis: High v. Low linked Fate on Participation ##
# t tests - difference in mean between high linked, low linked among LGBT
# table made in latex, see .tex file
freq(lgbt_data$linked.1) # 0 = no linked fate, 1 = some or alot of linked fate
t1.lgbt<-t.test(lgbt_data$discrim_gendersexuality~lgbt_data$linked.1)
t1.lgbt #lgbts high in linked fate are significantly more likely to report experience with discrim.

t2.lgbt<-t.test(lgbt_data$discrim_lgbt~lgbt_data$linked.1)
t2.lgbt #lgbts high in linked fate significantly more likely to perceive discrim toward lgbt

t3.lgbt<-t.test(lgbt_data$know_lgbt~lgbt_data$linked.1)
t3.lgbt #lgbts high in linked fate significantly more likely to know lgbt

t4.lgbt<-t.test(lgbt_data$pid_scale~lgbt_data$linked.1)
t4.lgbt #lgbts high in linked more democratic

t5.lgbt<-t.test(lgbt_data$ideology~lgbt_data$linked.1)
t5.lgbt #lgbts high in linked more liberal

t6.lgbt<-t.test(lgbt_data$educ~lgbt_data$linked.1)
t6.lgbt #lgbts high in linked fate more educated

t7.lgbt<-t.test(income~linked.1,data=lgbt_data)
t7.lgbt #lgbts high in linked fate tend to have more income, but theyre still in same range.

## Appendix F: Regression Outputs, Participation ##

# Table A5
library(stargazer)

newa5particindextable<-stargazer(s1,s2,s3,s4,s5,s6,s7,
                                 type="text", out="weights_particindextablenew.html",
                                 ci.level=0.95,star.cutoffs=c(0.05,0.01,0.001),
                                 dep.var.labels = "Political Participation Index",
                                 covariate.labels = c("Linked Fate","Income","Education","Political Interest","PID","Ideology","White","Age","Female"),
                                 column.labels = c("Linked Fate (Full)"," + Theoretical (Full)","All Covariates (Full)","Linked Fate (LGBTQ)","+ Theoretical (LGBTQ)","All Covariates (LGBTQ) ","All Covariates (Straight)"),
                                 title= "Table A5: Multiple Regression, Political Participation Index",
                                 notes = "CMPS 2016 ACS sample weights used.")
newa5particindextable
#Table A6
newa6participation<-stargazer(s6,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10, type="text", out="a6participation.html",
                           ci.level=0.95,star.cutoffs=c(0.05,0.01,0.001),covariate.labels = c("Linked Fate","Income","Education","Political Interest","PID","Ideology","White","Age","Female"),
                           dep.var.labels = c("Participation Index","Voter Reg","Vote 2016",
                                              "Protest","Contact","Donate","Discuss Pol","Community Org","Boycott","Civil Society"),
                           title = "Table A6: Regression Results, Political Participation, LGBTQ Sample")
newa6participation

## Appendix G: Identity and Linked Fate
#make Bisexual men variable

lgbt_data$bimen<-ifelse(lgbt_data$bisexual =='1' & lgbt_data$male== '1',1,0)
freq(lgbt_data$bimen)
lgbt_data$biwomen<-ifelse(lgbt_data$bisexual =='1' & lgbt_data$female== '1',1,0)
#IMPORT BI VARIABLE INTO MAIN DATASET
#Bisexual women variable
freq(cmps2016$bisexual)
cmps2016$biwomen<-ifelse(cmps2016$bisexual =='1' & cmps2016$female== '1',1,0)
freq(cmps2016$biwomen)
#bisexual men variable
cmps2016$bimen<-ifelse(cmps2016$bisexual =='1' & cmps2016$male== '1',1,0)
freq(cmps2016$bimen)

aggregate(linkedfate~biwomen, data=lgbt_data,FUN=mean)
aggregate(linkedfate~bimen, data=lgbt_data,FUN=mean)

#Table A7:

table2lm<-lm(linkedfate~gay+lesbian+bisexual+transgender+queer+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white1,data=cmps2016, weights = WEIGHT)
summary(table2lm)

bianalysis<-lm(linkedfate~gay+lesbian+bimen+biwomen+transgender+queer+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white1,data=cmps2016, weights = WEIGHT)
summary(bianalysis)

tablea7<-stargazer(table2lm,bianalysis,
                   type="text",
                   out="bianalysis.html",
                   ci.level=0.95,
                   star.cutoffs=c(0.05,0.01,0.001),
                   dep.var.labels = c ("Queer Linked Fate"),
                   title = "Table A7: Regression Results, Queer Linked Fate by Identity",
                   notes = "CMPS 2016 ACS sample weights used. Models include controls.")
tablea7

#Table A8:
newracelm<-lm(linkedfate~black+latino+asian+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female,data=lgbt_data,weights = WEIGHT)
summary(newracelm)

tablea8<-stargazer(newracelm,
                   type="text",
                   out="newracelm.html",
                   ci.level=0.95,
                   star.cutoffs=c(0.05,0.01,0.001),
                   dep.var.labels = c ("Queer Linked Fate"),
                   title = "Table A8: Regression Results,  Linked Fate by Racial Identity",
                   notes = "CMPS 2016 ACS sample weights used. Models include controls.")
tablea8

## Appendix H: Regressions, Determinants and Identity
# Table A9
# lgbtq dummy as IV.
h1<-lm(linkedfate~lgbtq.dummy,data=cmps2016,weights=WEIGHT)
summary(h1)
# lgbtq + theory covars
h2<-lm(linkedfate~lgbtq.dummy+discrim_lgbt+discrim_gendersexuality+know_lgbt,data=cmps2016,weights=WEIGHT)
summary(h2)
# lgbtq + theory + political covars
h3<-lm(linkedfate~lgbtq.dummy+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1,data=cmps2016,weights=WEIGHT)
summary(h3)
# lgbtq + theory + pol + demographic
h4<-lm(linkedfate~lgbtq.dummy+discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white,data=cmps2016,weights=WEIGHT)
summary(h4)

# theory covars
h5<-lm(linkedfate~discrim_lgbt+discrim_gendersexuality+know_lgbt,data=lgbt_data,weights=WEIGHT)
summary(h5)

# theory + pol
h6<-lm(linkedfate~discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1,data=lgbt_data,weights=WEIGHT)
summary(h6)

# theory + pol + demographic
h7<-lm(linkedfate~discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white,data=lgbt_data,weights=WEIGHT)
summary(h7)

#straight all
h8<-lm(linkedfate~discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white, data=straight_data,weights=WEIGHT)
summary(h8)

tablea9<-stargazer(h1,h2,h3,h4,h5,h6,h7,h8,
                   type="text",
                   out="h18.html",
                   ci.level=0.95,
                   star.cutoffs=c(0.05,0.01,0.001),
                   align=T,
                   dep.var.labels = c("Queer Linked Fate"),
                   covariate.labels = c("Queer ID","Perceive LGBT Discrim","Experience LGBT Discrim","LGBT Network","PID","Ideology","Political Interest","Age","Income","Education","Female","White"),
                   column.labels = c("Queer ID",
                                     "Theoretical Cov","+ Political Cov","All Covariates","Queer Sample: Theoretical Cov","Queer Sample: + Political Cov","LGBTQ Sample: All Covariates","Straight Sample, All Covariates"),
                   title = "Table A9: Regression Results, Determinants of Queer Linked Fate")
tablea9

## Appendix I: Discrimination Exploratory Analysis
# Appendix Figure  1
determin.lgbt.w<-lm(linkedfate~discrim_lgbt+discrim_gendersexuality+know_lgbt+pid_scale+ideology+polinterest.1+age+income+educ+female+white,data=lgbt_data,weights=WEIGHT)
summary(determin.lgbt.w)

appendixfig1<-plot_models(determin.lgbt.w,
                          p.threshold = c(0.05,0.01,0.001),
                          show.p=T,
                          spacing = 2,
                          colors= c("black"),
                          show.legend=F,
                          axis.labels = c("White",
                                          "Female",
                                          "Education",
                                          "Income",
                                          "Age",
                                          "Pol Interest",
                                          "Ideology",
                                          "PID",
                                          "LGBT Network",
                                          "Experience Discrim",
                                          "Perceive LGBT Discrim"),
                          title = "Appendix I, Figure 1: Predictors of Queer Linked Fate",
                          wrap.title=60)
appendixfig1
appendixfig<-appendixfig1+geom_hline(yintercept = 0, color = "red", size = 0.15)+ylim(-0.50,0.50) +set_theme(title.size = 1.1)+theme(plot.title=element_text(hjust=0.5))
appendixfig
ggsave("appendixfig.pdf")


